<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字练习</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的数" id="i1">
<input type="button" value="猜一猜" onclick="f()">
<div id="i2"></div>


<script>
  //得到1-100随机整数
  let x=parseInt(Math.random()*100)+1
  let count=0;
function f() {
    count++
  if(i1.value>x){
    i2.innerText="猜大了"
  }else if(i1.value<x){
    i2.innerText="猜小了"
  }else{
    i2.innerText="第"+count+"次猜对了"

  }
}



</script>

</body>
</html>